package kr.co.bettersoft.sendme.activity;

import kr.co.bettersoft.sendme.util.SendMeActivityManager;
import kr.co.bettersoft.sendme.util.SendMeConstant;
import kr.co.bettersoft.sendme.activity.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class SendMeMainMenuActivity extends Activity implements OnClickListener{
	
	// 액티비티 매니저를 가져 온다.
	private SendMeActivityManager sendMeActivityManager = SendMeActivityManager.getInstance();
	
	// 마스터 암호.
	private String MASTER_PASSWORD = "";
			
	// 퍼블릭 암호.
	private String PUBLIC_PASSWORD = "";
	
	// 기능 모드.(MASTER/PUBLIC)
	private String FUNCTION_MODE = "";
			
	// 사용자 휴대 전화번호.
	private String PHONE_NUMBER = "";


	ImageButton imageButtonTopBack;
	
	
	View menuAudioMessageBtnLayout;
	View menuTempMassageBtnLayout;
	View menuReservationBtnLayout;
	View menuSettingBtnLayout;
	View menuReceiveMessageBtnLayout;
	View MenuDownloadMessageBtnLayout;
	View menuBlockListBtnLayout;
	
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// 커스텀 타이블 바를 설정 한다.
		Window window = getWindow();
		window.requestFeature(Window.FEATURE_CUSTOM_TITLE);
				
		setContentView(R.layout.activity_send_me_main_menu);
		
		window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar_03);
		
		// 액티비티 매니저에 담는다.
		sendMeActivityManager.addActivity(this);
				
		// 설정파일을 가져 온다.
		this.confirmNotification();
		
		// 뒤로 가기 화살표 버튼을 설정 한다.
		imageButtonTopBack = (ImageButton)findViewById(R.id.imageButtonTopBack);
		imageButtonTopBack.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				// 화면을 닫는다.
				mainMenuFinish();
			}
		});
		
		menuAudioMessageBtnLayout = findViewById(R.id.menuAudioMessageBtnLayout);
		menuTempMassageBtnLayout = findViewById(R.id.menuTempMassageBtnLayout);
		menuReservationBtnLayout = findViewById(R.id.menuReservationBtnLayout);
		menuSettingBtnLayout = findViewById(R.id.menuSettingBtnLayout);
		menuReceiveMessageBtnLayout = findViewById(R.id.menuReceiveMessageBtnLayout);
		MenuDownloadMessageBtnLayout = findViewById(R.id.MenuDownloadMessageBtnLayout);
		menuBlockListBtnLayout = findViewById(R.id.menuBlockListBtnLayout);
		menuAudioMessageBtnLayout.setOnClickListener(this);
		menuTempMassageBtnLayout.setOnClickListener(this);
		menuReservationBtnLayout.setOnClickListener(this);
		menuSettingBtnLayout.setOnClickListener(this);
		menuReceiveMessageBtnLayout.setOnClickListener(this);
		MenuDownloadMessageBtnLayout.setOnClickListener(this);
		menuBlockListBtnLayout.setOnClickListener(this);
		
	}

	
	/*
	 * 하단 녹음/메뉴 버튼 클릭 리스너
	 */
	@Override
	public void onClick(View v) {
		
		Intent intent;
		
		switch (v.getId()) {
			// 음성 메시지
		case R.id.menuAudioMessageBtnLayout:
			intent = new Intent(this, SendMeFriendActivity.class);
			startActivity(intent);
			mainMenuFinish();
			break;
			
			//  임시 보관함
		case R.id.menuTempMassageBtnLayout:
			intent = new Intent(this, SendMeTempMessageListActivity.class);
			startActivity(intent);
			mainMenuFinish();
			break;
			
			// 예약 메시지
		case R.id.menuReservationBtnLayout:
			intent = new Intent(this, SendMeReservationMessageListActivity.class);
			startActivity(intent);
			mainMenuFinish();
			break;
			
			// 설정
		case R.id.menuSettingBtnLayout:
			intent = new Intent(this, SendMeSettingsActivity.class);
			startActivity(intent);
//			mHandler.sendMessage(mHandler.obtainMessage(THREAD_RECORDING_RESUME));
			mainMenuFinish();
			break;

			// 받은 메시지
		case R.id.menuReceiveMessageBtnLayout:
			intent = new Intent(this, SendMeReceiveVoiceListActivity.class);
			startActivity(intent);
			mainMenuFinish();
			break;
			
			// 저장 메시지
		case R.id.MenuDownloadMessageBtnLayout:
			intent = new Intent(this, SendMeDownloadMessageListActivity.class);
			startActivity(intent);
			mainMenuFinish();
			break;
			
			// 차단 목록
		case R.id.menuBlockListBtnLayout:
			intent = new Intent(this, SendMeBlockListActivity.class);
			startActivity(intent);
			mainMenuFinish();
			break;
			
		}
	}
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.send_me_main_menu, menu);
		return true;
	}

	/**
	 * SharedPreference 정보를 확인 한다.
	 */
	public void confirmNotification() {
		SharedPreferences mSharedPreference = getSharedPreferences(SendMeConstant.SENDME_PREFERENCE, Activity.MODE_PRIVATE);
		
		MASTER_PASSWORD = mSharedPreference.getString("master_password", "");
		PUBLIC_PASSWORD = mSharedPreference.getString("public_password", "");
		FUNCTION_MODE = mSharedPreference.getString("function_mode", "");
		PHONE_NUMBER = mSharedPreference.getString("phone_number", "");
	}
	
	/**
	 * 뒤로 가기 버튼을 정의 한다.
	 * 앱 실행시의 암호 입력화면이기 때문에 뒤로가기 버튼을 터치하면 앱을 종료 한다.
	 */
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		mainMenuFinish();
	}
	
	// 화면을 닫는다.
	public void mainMenuFinish(){
		sendMeActivityManager.removeActivity(SendMeMainMenuActivity.this);
		finish();
	}
	
	
	
}
